<template>
  <div class="warpper-box">
    <div class="inner_box">

      <div class="bur-box">
        <el-button type="primary" @click="$refs.createMyStore.openStoreForm()" size="mini">申请入库</el-button>
        <el-button type="text" @click="rewier" icon="el-icon-download">泸州老窖发展投资集团有限公司供应商管理系统使用说明书.pdf</el-button>
      </div>

      <el-row :gutter="10">
        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>通知公告浏览</span>
            </div>
            <div class="line-po" v-if="noticeList.length >=1">
              <div class="lis" v-for="(item,index) in noticeList" :key="index" @click="detailOpen(1,item)">
                <div class="lis-label">
                  <label>{{item.title}}</label>
                </div>
                <label>{{item.publishTime | formatDate}}</label>
              </div>
            </div>
            
            <div class="line-po" v-if="noticeList.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>年度考核评价结果</span>
            </div>
            <div class="line-po" v-if="labour.length >=1">
              <div class="lis" v-for="(item,index) in labour" :key="index" @click="detailOpen(2,item)">
                <div class="lis-label">
                  <label>{{item.categoryName}}</label>
                </div>
                <label>{{item.totalDeduction}}分</label>
              </div>
            </div>
             <div class="line-po" v-if="labour.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>入库记录</span>
            </div>
            <div class="line-po" v-if="supplierStoreList.length >=1">
              <div class="lis" v-for="(item,index) in supplierStoreList" :key="index" @click="detailOpen(3,item,1)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label>{{item.storeApplyTime | formatDate}}</label>
              </div>
            </div>
            <div class="line-po" v-if="supplierStoreList.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

         <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>入库申请通过</span>
            </div>
            <div class="line-po" v-if="storePass.length >=1">
              <div class="lis" v-for="(item,index) in storePass" :key="index" @click="detailOpen(3,item,1)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label>{{item.storeCheckTime | formatDate}}</label>
              </div>
            </div>
            <div class="line-po" v-if="storePass.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>入库申请驳回</span>
            </div>
            <div class="line-po" v-if="storeError.length >=1">
              <div class="lis" v-for="(item,index) in storeError" :key="index" @click="detailOpen(3,item,2)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label>{{item.storeCheckTime | formatDate}}</label>
              </div>
            </div>
             <div class="line-po" v-if="storeError.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>资料更新通过</span>
            </div>
            <div class="line-po" v-if="storePassInfo.length >=1">
              <div class="lis" v-for="(item,index) in storePassInfo" :key="index" @click="detailOpen(3,item,1)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label>{{item.storeCheckTime | formatDate}}</label>
              </div>
            </div>
            <div class="line-po" v-if="storePassInfo.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>资料更新驳回</span>
            </div>
            <div class="line-po" v-if="storeErrorInfo.length >=1">
              <div class="lis" v-for="(item,index) in storeErrorInfo" :key="index" @click="detailOpen(3,item,2)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label>{{item.storeCheckTime | formatDate}}</label>
              </div>
            </div>
            <div class="line-po" v-if="storeErrorInfo.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

         <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>账号被移入暂停菜单</span>
            </div>
            <div class="line-po" v-if="storeBick.length >=1">
              <div class="lis" v-for="(item,index) in storeBick" :key="index" @click="detailOpen(3,item,1)">
                <div class="lis-label">
                  <label>{{item.applyCategoryName}}</label>
                </div>
                <label v-if="item.pauseType == '1'">移入时间（{{item.pauseTime | formatDate}}）</label>
                <label v-if="item.pauseType == '2'">到期时间（{{item.expireTime | formatDate}}）</label>
              </div>
            </div>
             <div class="line-po" v-if="storeBick.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

        <el-col :span="12">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>入库到期提醒</span>
            </div>
            <div class="line-po" v-if="expireList.length >=1">
              <div class="lis" v-for="(item,index) in expireList" :key="index">
                <div class="lis-label">
                  <label>{{item.name}}【{{item.notificationContent}}】</label>
                  <label>{{item.notificationTime | formatDate}}</label>
                </div>
              </div>
            </div>
             <div class="line-po" v-if="expireList.length === 0">
              <el-empty :image-size="98"></el-empty>
            </div>
          </el-card>
        </el-col>

       
      </el-row>
      <myStore ref="createMyStore" title="申请入库" @success="onSuccess"></myStore>
      <infoStore ref="createInfoStore"></infoStore>
      <noticeDetail ref="createNoticeDetail"></noticeDetail>
      <evaluateDetail ref="createEvaluateDetail" />
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import { mapGetters, mapActions } from "vuex";
import { getMyNoticeList,setNoticeRecord,getSupplierStorePage,getEvaluationPage,getJiJiangDaoQi } from "@/api/supplier_api"
import myStore from '@/views/supplier/supplierModel/my_store.vue'
import infoStore from '@/views/supplier/supplierModel/info_store.vue'
import noticeDetail from "@/views/supplier/notice/notice_detal.vue";
import evaluateDetail from "@/views/supplier/evaluate/evaluate_detail.vue";
export default {
  name: "supplierHome",
  components: {
    myStore,
    infoStore,
    noticeDetail,
    evaluateDetail
  },
  data() {
    return {
      noticeList:[],
      labour: [],
      storePass: [],
      storeError: [],
      storePassInfo: [],
      storeErrorInfo:[],
      storeBick: [], //暂停
      supplierStoreList: [],//入库记录
      expireList:[],
      params:{pageNum:1,pageSize:5}
    };
  },
  filters: {
      formatDate(value) {
          if (!value) {
              return ''
          }
          return moment(value).format("YYYY-MM-DD")
      }
  },
  computed: {
    ...mapGetters(["permission_user"])
  },
  mounted() {
    this.getNoticeData()
    this.getStoreData('1')
    this.getStoreData('2')
    this.getStoreInfoData('1')
    this.getStoreInfoData('2')
    this.getSupplierStoreAll()
    this.getSupplierStoreBick()
    this.getMyEvaluation()
    this.getexpireList()
  },
  methods: {
    rewier() {
      window.open("/file/泸州老窖发展投资集团有限公司供应商管理系统使用说明书.pdf","_blank");
    },
    onSuccess() {
       this.getSupplierStoreAll()
    },
    //获取我的公告
    async getNoticeData() {
      let param = {}
      let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.receiverId = supplier.id
      }
      param.pageNum = this.params.pageNum
      param.pageSize = this.params.pageSize
      const { data } = await getMyNoticeList(param)
      this.noticeList = data.list
    },
    //入库驳回和通过
    async getStoreData(storeStatus) {
      let param = {}
     let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.supplierId = supplier.id
      }
      param.pageNum = this.params.pageNum
      param.storeStatus = storeStatus
      param.storeType = '1'; // 入库是1 资料是2
      param.pageSize = this.params.pageSize
      const { data } = await getSupplierStorePage(param)
      if (storeStatus == '1') {
        this.storePass = data.list
      } else {
       const result = data.list.filter(v=> !v.newUpdateId && !v.newUpdateStatus)
        this.storeError = result
      }
    },
    //资料通过与驳回
    async getStoreInfoData(storeStatus) {
       let param = {}
     let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.supplierId = supplier.id
      }
      param.storeStatus = storeStatus;
      param.pageNum = this.params.pageNum
      param.pageSize = this.params.pageSize;
      param.storeType = '2'; // 入库是1 资料是2
      const { code, data } = await getSupplierStorePage(param);
      if (storeStatus == '1') {
        this.storePassInfo = data.list
      } else {
        this.storeErrorInfo = data.list
      }
    },
    //获取入库记录
    async getSupplierStoreAll() {
      let param = {}
      param.pageNum = this.params.pageNum
      param.pageSize = this.params.pageSize;
      param.storeType = "1"
      let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.supplierId = supplier.id
      }
      const { code, data } = await getSupplierStorePage(param);
      if (code == 200) {
        this.supplierStoreList = data?.list ?? []
      }
    },
    //到期
     async getexpireList() {
      let param = {};
      param.pageNum = this.params.pageNum;
      param.pageSize = this.params.pageSize;
      param.bizType = "ZLGX";
      const { code, data } = await getJiJiangDaoQi(param);
      if (code == 200) {
        this.expireList = data.list;
      }
    },
    //被暂停
    async getSupplierStoreBick() {
      let param = {};
      param.pageNum = this.params.pageNum
      param.pageSize = this.params.pageSize;
      param.isPaused = 1
      let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.supplierId = supplier.id
      }
      const { code, data } = await getSupplierStorePage(param);
      if (code == 200) {
        this.storeBick = data?.list ?? [];
      }
    },
    //获取评价
    async getMyEvaluation() {
       let param = {}
      let supplier = this.permission_user.purchaseSupplier
      if (supplier !== null && typeof supplier === 'object') {
        param.supplierId = supplier.id
      }
        param.pageNum =1
      param.pageSize = 5
      const { data } = await getEvaluationPage(param)
        this.labour = data?.list ?? []
    },
    getPath(url,row){
      this.$router.push({name:url,params: {   
        activeName: String(row.jobStateId),   
      } });
    },
    morePath(type){
      // this.$router.push({name:url,params: {   
      //   activeName: String(row.jobStateId)
      // } });
    },

    detailOpen(type, row, result) {
      if (type == 1) {
        if (row.isRead == 0) {
          this.editNoticeRecord(row.recordId)
        }
        this.$refs.createNoticeDetail.openDetail(row)
      }
      if (type == 3) {
        row.id = row.applyId
        this.$refs.createInfoStore.openDetail(row,result)
      }
      if (type == 2) {
        let txt = row.supplierCategory == 1 ? '（工程和货物类）' : '（服务类）'
         let title = `泸州老窖发展投资集团有限公司${txt}【${row.supplierName}】【${row.categoryName}】考核评价清单`
        this.$refs.createEvaluateDetail.openForm(
          row,
          title
        );
      }
    },
    async editNoticeRecord(id) {
      await setNoticeRecord(id)
    }
  }
};
</script>
<style>
.lis{
  display: flex;
  align-items: center;
  border-bottom:1px solid #EBEEF5;
  padding:6px 0;
}
.lis:hover label{
  color: #409EFF;
  cursor: pointer;
}
.lis-label{
  flex: 1;
  margin-right: 20px;
  line-height: 28px;
}
.bur-box{
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.line-po{
  height: 224px;
}
</style>
